package org.rcy.framework.file.upload;

import java.io.File;
import java.io.RandomAccessFile;

/**
 * @author 吴康桥
 * @Description
 * @date 2022/12/12 10:03
 */


public class FileUploadService {
	private final int BYTES_PER_SLICE = 1<<20;

	public void sliceUpload(byte[] bytes,String fileName,int index,int size,String storePath) {
		File dest = new File(storePath+"/"+fileName);
		if(!dest.getParentFile().exists()){
			dest.getParentFile().mkdirs();
		}
		try(RandomAccessFile randomAccessFile = new RandomAccessFile(dest,"rw")){
			randomAccessFile.seek(index*BYTES_PER_SLICE);
			randomAccessFile.write(bytes);
		}catch (Exception e){

		}
	}
}
